#include <iostream>

#include <gtest/gtest.h>

#include "melon/client/thrift_client_pool.h"
// #include "SessionService.h"
#include "im/adapters/bang_robot_adapter.h"

using imserver::BangRobotServiceClient;
using melon::client::ClientPool;

using namespace imserver;

void * ThreadFun(void *) {
  for (int i = 0; i < 10000; ++i) {
    int ret = BangRobotAdapter::Instance().DispatchPresence(127646882 + i, std::string("c7de772208bda3f0b3f09aa1fd1cccc4_0"), SessionType::WEB, 2);
    std::cout << "DispatchPresence " << i << " ret=" << ret << std::endl;
    ret = BangRobotAdapter::Instance().BroadcastClient(127646882 + i, 127646882, 2);
    std::cout << "DispatchPresence " << i << " ret=" << ret << std::endl;

    ImMessage message;
    message.sender = 127646882 + i;
    message.receiver = 127646882;
    message.body = "bang_robot_test_message";
    ret = BangRobotAdapter::Instance().DispatchMessage(message, 2);
    std::cout << "DispatchMessage " << i << " ret=" << ret << std::endl;
  }
  return NULL;
}

const int kThreadCount = 20;

int main() {
  LOG_INIT("./test.log", "DEBUG");
  pthread_t ts[kThreadCount];

  for (int i = 0; i < kThreadCount; ++i) {
    pthread_create(&ts[i], NULL, ThreadFun, NULL);
  }

  for (int i = 0; i < kThreadCount; ++i) {
    pthread_join(ts[i], NULL);
  }
  return 0;
} 
